package com.zto.design.observer.simple;

/**
 * @program: sch-diy-parent
 * @description: 事件类 -- 具体被观察者
 * @author: sch
 * @create: 2020-11-27 14:22
 **/

import com.zto.design.observer.Callback;
import com.zto.design.observer.Observerable;

public class Event implements Observerable<Callback> {
    /**
     * 事件触发函数--通知订阅者
     */
    @Override
    public void emit() {
        for (Callback callback : callbackList) {
            //触发观察者相关动作
            callback.run(this);
        }
    }

    /**
     * 注册事件
     */
    @Override
    public void registerEvent(Callback callback) {
        callbackList.add(callback);
    }

    /**
     * 移除事件
     *
     * @param callback
     */
    @Override
    public void removeEvent(Callback callback) {
        callbackList.remove(callback);
    }
}
